<?php
global $_GPC, $_W;
$weid = $this->_weid;
$setting = $this->getSetting();
$GLOBALS['frames'] = $this->getMainMenu();

$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';


if ($operation == 'display') {
    $list = pdo_fetchall("SELECT * FROM " . tablename('weisrc_dish_marketinglevel') . " WHERE weid = :weid {$strwhere} ORDER BY storecount DESC,id
DESC", array(':weid' => $weid));

} elseif ($operation == 'post') {
    load()->func('tpl');
    $id = intval($_GPC['id']);
    if (!empty($id)) {
        $type = pdo_fetch("SELECT * FROM " . tablename('weisrc_dish_marketinglevel') . " WHERE id = '$id'");
    }
    if (checksubmit('submit')) {
        if (empty($_GPC['title'])) {
            message('请输入等级名称！');
        }

        $data = array(
            'weid' => $weid,
            'title' => $_GPC['title'],
            'storecount' => intval($_GPC['storecount']),
            'fee_rate' => floatval($_GPC['fee_rate']),
            'dateline' => TIMESTAMP
        );
        if (!empty($id)) {
            pdo_update('weisrc_dish_marketinglevel', $data, array('id' => $id));
        } else {
            pdo_insert('weisrc_dish_marketinglevel', $data);
        }
        message('操作数据成功！', $this->createWebUrl('marketinglevel', array('op' => 'display')), 'success');
    }
} elseif ($operation == 'delete') {
    $id = intval($_GPC['id']);
    $type = pdo_fetch("SELECT id FROM " . tablename('weisrc_dish_marketinglevel') . " WHERE id = '$id'");
    if (empty($type)) {
        message('抱歉，数据不存在或是已经被删除！', $this->createWebUrl('marketinglevel', array('op' => 'display')), 'error');
    }
    pdo_delete('weisrc_dish_marketinglevel', array('id' => $id, 'weid' => $weid));
    message('数据删除成功！', $this->createWebUrl('marketinglevel', array('op' => 'display')), 'success');
}
include $this->template('web/marketinglevel');